function showpic(obj) {
    var source = "/upload/question/" + obj;
    $("#image").attr("src", source);
    $("#image").css("display", "block");
}


var currentGid;

//RRR
function modify(obj) {
    $("#create").fadeOut();
    $("#warning").slideDown(500);
    $.post("faq", {
        id: obj.value,
        optional: "RRR"
    }, function (result) {
        console.log(result);
        if (result["err"] !== null) {
            alert("读取数据出现错误!")
        }
        currentGid = obj.value;
        $("#rdesc").val(result["obj"]["Desc"]);
        $("#ra").val(result["obj"]["Option"][1]);
        $("#rb").val(result["obj"]["Option"][2]);
        $("#rc").val(result["obj"]["Option"][3]);
        $("#rd").val(result["obj"]["Option"][4]);
        $("#re").val(result["obj"]["Option"][5]);
        $("#rf").val(result["obj"]["Option"][6]);
        $("#rg").val(result["obj"]["Option"][7]);
        $("#rreason").val(result["obj"]["Reason"]);

        var radio = $(".reffect");
        var correct = result["obj"]["Correct"];
        for (i in radio) {
            if (parseInt(i) === parseInt(correct)) {
                radio[i - 1].click()
            }
        }
    })
}

//DDD UUU
$(function () {
    var modal = $("#warning");
    $("#miniclose").click(function () {
        modal.fadeOut()
    });
    $("#rdelete").click(function () {
        $.post("faq", {
            id: currentGid,
            optional: "DDD"
        }, function (result) {
            console.log(result);
            console.log(result["err"]);
            if (result["err"] === null) {
                alert("删除成功!");
                window.location.reload()
            } else {
                alert("删除失败!");
                modal.fadeOut(500);
            }
        })
    });
    $("#rcancle").click(function () {
        modal.fadeOut(500);

    });


    $("#rsure").click(function () {
        var state;
        var radio = $(".reffect");
        for (var i = 0; i < radio.length; i++) {
            if (radio[i].checked === true && i <= 7) {
                state = i + 1
            }

        }
        var formData = new FormData($('#udinfo')[0]);
        formData.append("optional", "UUU");
        formData.append("correct", state);
        formData.append("id", currentGid);
        var opt = {
            1: $("#ra")[0].value,
            2: $("#rb")[0].value,
            3: $("#rc")[0].value,
            4: $("#rd")[0].value,
            5: $("#re")[0].value,
            6: $("#rf")[0].value,
            7: $("#rg")[0].value
        };
        console.log(opt);
        formData.append("opt", JSON.stringify(opt));
        $.ajax({
            type: "POST",
            url: "faq",
            data: formData,
            processData: false,
            contentType: false,
            success: function (result) {
                console.log(result);
                if (result["err"] === null) {
                    alert("修改成功!");
                    window.location.reload()
                } else {
                    alert("修改失败!");
                    modal.fadeOut(500);
                }
            }
        })
    })
});

//CCC
$(function () {
    modal = $("#create");
    $("#createstudent").click(function () {
        $("#warning").fadeOut(500);
        modal.slideDown()
    });

    $("#ccancle").click(function () {
        modal.fadeOut(500);
    });
    $("#csure").click(function () {
        var state;
        var radio = $(".ceffect");
        for (var i = 0; i < radio.length; i++) {
            if (radio[i].checked === true && i <= 7) {
                state = i + 1
            }

        }
        var formData = new FormData($('#createinfo')[0]);
        formData.append("optional", "CCC");
        formData.append("correct", state);
        var opt = {
            1: $("#ca")[0].value,
            2: $("#cb")[0].value,
            3: $("#cc")[0].value,
            4: $("#cd")[0].value,
            5: $("#ce")[0].value,
            6: $("#cf")[0].value,
            7: $("#cg")[0].value
        };
        formData.append("opt", JSON.stringify(opt));
        $.ajax({
            type: "POST",
            url: "faq",
            data: formData,
            processData: false,
            contentType: false,
            success: function (result) {
                console.log(result);
                if (result["err"] === null && result["row"] === 1) {
                    alert("增加成功!");
                    window.location.reload()
                } else {
                    alert("增加失败,请确保没有填写重复的身份证号");
                    modal.fadeOut(500);
                }
            }
        })
    });
    $("#miniclose2").click(function () {
        modal.fadeOut()
    })
});
